#!/bin/bash
MYLOGFILE="/var/www/html/stop.html"
source /usr/bin/gxcc_common.sh

#保证该脚本在同一时间只能有一个执行
if (set -o noclobber;echo "nothing" > ${WEB_DIR}/${LOCK_FILE_STOP}) 2> /dev/null;then
    trap 'rm -f ${WEB_DIR}/${LOCK_FILE_STOP};exit $?' INT TERM EXIT

    echo "<!DOCTYPE html><html>" > $MYLOGFILE
    echo "<p><a href=\"index.html\" target=\"_blank\"><b>本节点：${THIS_NODE_IP}</b></a></p>" >> $MYLOGFILE
    echo "<p><b>脚本名称：${BASH_SOURCE[0]}</b></p>" >> $MYLOGFILE
    echo "<p><b>执行时间：$(date "+%Y-%m-%d %H:%M:%S")</b></p>" >> $MYLOGFILE

    if [ `whoami` != "root" ];then echo "<p>须以root用户执行，执行结束</p></html>" >> $MYLOGFILE;exit 1;fi
    if ! check_this_node_ip $MYLOGFILE;then echo "<p>本节点IP设置错误，执行结束</p></html>" >> $MYLOGFILE;exit 1;fi
    
    stop_this_node $MYLOGFILE
    if [ $? -eq 0 ];then
	echo "<p>本节点：已停止</p>" >> $MYLOGFILE
	echo "<p>STATE:STOPPED/$(date "+%Y-%m-%d %H:%M:%S")</p>" >> $MYLOGFILE
    else
	echo "<p>本节点：停止失败</p>" >> $MYLOGFILE
    fi
    
    echo "<p>执行结束</p></html>" >> $MYLOGFILE
    cp $MYLOGFILE /var/www/html/index.html
else
    echo "重复执行"
fi
